package io.scnb.coupon.customer.dao.converter;

import io.scnb.coupon.customer.api.enums.CouponStatus;

import javax.persistence.AttributeConverter;

public class CouponStatusConverter implements AttributeConverter<CouponStatus, Integer> {

    // 如果需要把DB里的值转换成enum对象，就采用这种方式就好了
    // 利用泛型模板继承AttributeConverter
    
    @Override
    public Integer convertToDatabaseColumn(CouponStatus couponStatus) {
        return couponStatus.getCode();
    }

    @Override
    public CouponStatus convertToEntityAttribute(Integer code) {
        return CouponStatus.convert(code);
    }
}
